package com.example.yx.demo14;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class A14 {
    public static void main(String[] args) {
        Proxy proxy = new Proxy();
        Target target = new Target();
        proxy.setMethodInterceptor(new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                System.out.println("before");
//                return method.invoke(target,objects);反射调用

                return methodProxy.invoke(target,objects);//内部无反射，结合目标来使用

//                return methodProxy.invokeSuper(o,objects);//内部无反射，结合代理使用
            }
        });

        proxy.save();
        proxy.save(1);
        proxy.save(2L);
    }
}
